package cn.web03.jpa.repository;

import cn.web03.domain.Person;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface PersonRepository extends JpaRepository<Person, Long> {

    List<Person> findByAddress(String address);

    Person findByNameAndAddress(String name, String address);

    List<Person> findByAddressOrderByIdDesc(String address);

    // 分页
    Page<Person> findByAddress(String address, Pageable pageable);

    //
    @Query("select p from Person p where p.name = :name and p.address = :address")
    Person withNameAndAddress(@Param("name") String name, @Param("address") String address);
}
